import Vue from 'vue'
import VueRouter from 'vue-router'
import {routers} from './router'
import Util from '../libs/utils'
import $ from '@/libs/jquery-vender.js'

Vue.use(VueRouter)

// 路由配置
const RouterConfig = {
  // mode: 'history',
  routes: routers
}

export const router = new VueRouter(RouterConfig)

router.beforeEach((to, from, next) => {
  Util.title(to.meta.title)
  if (to.path !== '/login') {
    if (!Util.isLogin()) {
      router.replace('/login')
      return
    }
  }
  next()
})

router.afterEach((to) => {
  if ($('.content-header h1').length > 0) {
    if (to.meta) {
      $('.content-header h1').html(to.meta.pageName)
    }
  }
})
